/*
 * This file is part of Grocy Android.
 *
 * Grocy Android is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Grocy Android is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Grocy Android. If not, see http://www.gnu.org/licenses/.
 *
 * Copyright (c) 2020-2023 by Patrick Zedler and Dominic Zedler
 */
package com.gitee.wsl.common.zxing

import android.preference.PreferenceManager
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData

class EmbeddedFragmentScannerBundle @JvmOverloads constructor(
    fragment: Fragment,
    containerScanner: CoordinatorLayout,
    barcodeListener: BarcodeListener,
    config: ZXingScanConfig
) : EmbeddedFragmentScanner(fragment.requireActivity()) {
    private val embeddedFragmentScanner: EmbeddedFragmentScanner

    init {
        embeddedFragmentScanner = EmbeddedFragmentScannerZXing(
            fragment,
            containerScanner,
            barcodeListener,
            config
        )
    }

    override fun setScannerVisibilityLive(scannerVisibilityLive: LiveData<Boolean>) {
        embeddedFragmentScanner.setScannerVisibilityLive(scannerVisibilityLive)
    }

    override fun setScannerVisibilityLive(
        scannerVisibilityLive: LiveData<Boolean>,
        supressNextScanStart: Boolean
    ) {
        embeddedFragmentScanner.setScannerVisibilityLive(
            scannerVisibilityLive,
            supressNextScanStart
        )
    }

    override fun onResume() {
        embeddedFragmentScanner.onResume()
    }

    override fun onPause() {
        embeddedFragmentScanner.onPause()
    }

    override fun onDestroy() {
        embeddedFragmentScanner.onDestroy()
    }

    override fun stopScanner() {
        embeddedFragmentScanner.stopScanner()
    }

    override fun startScannerIfVisible() {
        embeddedFragmentScanner.startScannerIfVisible()
    }

    override fun toggleTorch() {
        embeddedFragmentScanner.toggleTorch()
    }

    /*companion object {
        private fun useScannerFormat2d(fragment: Fragment): Boolean {
            val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(fragment.requireContext())
            return sharedPreferences.getBoolean(
                SCANNER.SCANNER_FORMAT_2D,
                SETTINGS_DEFAULT.SCANNER.SCANNER_FORMAT_2D
            )
        }
    }*/
}